<template>
  <div>
    <div class="ub inputBox ub-ver">
      <div class="ub mar_05 h_3 bg_w ub-pj ub-ac">
        <div class="fc-8b">设置新密码</div>
      </div>
      <div class="ub mar_05 h_3 ub-ac ub-pj">
        <input type="password" placeholder="新密码(6-14位字母和数字)" class="ub ub-f1" v-model="pd1">
        <div class="ub-img1 clear_icon" @click="pd1 = ''" v-show="pd1"></div>
      </div>
      <div class="ub mar_05 h_3 ub-ac ub-pj">
        <input type="password" placeholder="确认密码" class="ub ub-f1" v-model="pd2">
        <div class="ub-img1 clear_icon" @click="pd2 = ''" v-show="pd2"></div>
      </div>
      <div class="ub login mar_05 ub-pc ub-ac" @click='nextClc'>
        <div>提交</div>
      </div>
    </div>
  </div>
</template>
<script type="text/ecmascript-6">
// import headerDiv from 'components/header/header.vue';
export default {
  name: 'forgetPd',
  created: function () {
    this.$store.commit('changeHeader', {
      left: '返回',
      right: '',
      middle: '找回密码',
      ifshow: true,
      leftAction: '-1',
      leftIcon: 'leftIcon',
      rightAction: '',
      rightIcon: ''
    });
  },
  data: function () {
    return {
      pd1: '',
      pd2: ''
    };
  },
  methods: {
    // clearClick: function (e) {
    //   console.log(e)
    // },
    nextClc: function () {
      let self = this;
      let pd1 = this.pd1;
      let pd2 = this.pd2;
      let regPd = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
      if (!regPd.test(pd1) || !regPd.test(pd2)) {
        this.$store.dispatch('showTx', { text: '请输入合规的密码' });
        return false;
      }
      if (pd1 !== pd2) {
        this.$store.dispatch('showTx', { text: '两次输入的密码不一致' });
        return false;
      }
      let content = {
        'code': this.$store.state.forgetPd.yzm,
        'userPassword': this.$utils.getMD5(pd1),
        'userMobile': this.$store.state.forgetPd.phone
      }
      let data = this.$utils.getUserContent(content);
      console.log(data);
      this.$http.post(this.$RS.modifyForgetPwd, data).then(
        function (res) {
          // 响应成功回调
          this.$store.commit('closePop');
          res = res.body;
          console.log(res);
          if (res.code === 1000) {
            let content = {
              text: '修改成功',
              callback: function () {
                self.$router.go(-2)
              }
            }
            this.$store.dispatch('showTx', content);
            this.$store.commit('clearBoth');
          } else {
            console.log('out');
            this.$store.dispatch('showTx', { text: res.message });
          }
        },
        function (err) {
          console.log(err);
          this.$store.commit('closePop');
          // 响应错误回调
          this.$store.dispatch('showTx', { text: err.message || '网络错误，请重试' });
        }
      );
    }
  }

}
</script>

<style lang="stylus">
@import '../../stylus/base.styl';
</style>